/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * frmTraCuu.java
 *
 * Created on Dec 8, 2011, 10:21:31 AM
 */
package uit.qlks.from;

import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.sql.rowset.WebRowSet;
import javax.swing.JFrame;
import javax.swing.JOptionPane;
import javax.swing.table.DefaultTableModel;
import uit.ejb.dto.HoaDonDTO;
import uit.ejb.dto.KhachHangDTO;
import uit.qlks.baocao.BaoCao;
import uit.qlks.controller.hoadon.HoaDonController;
import uit.qlks.controller.khachhang.KhachHangController;
import uit.qlks.controller.phieuthue.PhieuThueController;

/**
 *
 * @author SVN - Team
 */
public class frmTraCuu extends javax.swing.JFrame {

    /** Creates new form frmTraCuu */
    KhachHangDTO kh=new KhachHangDTO();
    public static frmTraCuu _frmtc;
    public frmTraCuu() {
        initComponents();
         this.setResizable(false);
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jScrollPane1 = new javax.swing.JScrollPane();
        tbThongTin = new javax.swing.JTable();
        jLabel1 = new javax.swing.JLabel();
        btTraCuu = new javax.swing.JButton();
        txtHoTen = new javax.swing.JTextField();
        jLabel2 = new javax.swing.JLabel();
        jLabel3 = new javax.swing.JLabel();
        cmbDiaChi = new javax.swing.JComboBox();
        txtDiaChi = new javax.swing.JTextField();
        cmbDienThoai = new javax.swing.JComboBox();
        jLabel4 = new javax.swing.JLabel();
        txtDienThoai = new javax.swing.JTextField();
        cmbCMND = new javax.swing.JComboBox();
        jLabel5 = new javax.swing.JLabel();
        txtCMND = new javax.swing.JTextField();
        btnSua = new javax.swing.JButton();
        jLabel6 = new javax.swing.JLabel();
        btsuakh = new javax.swing.JButton();
        btnPrint = new javax.swing.JButton();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        setTitle("Tra Cứu Khách Hàng");
        addWindowListener(new java.awt.event.WindowAdapter() {
            public void windowClosed(java.awt.event.WindowEvent evt) {
                formWindowClosed(evt);
            }
        });
        addComponentListener(new java.awt.event.ComponentAdapter() {
            public void componentShown(java.awt.event.ComponentEvent evt) {
                formComponentShown(evt);
            }
        });

        tbThongTin.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {

            },
            new String [] {
                "Mã KH", "Tên KH", "Giới tính", "Địa chỉ", "Ngày sinh", "Số điện thoại", "CMND", "Quốc tịch"
            }
        ) {
            boolean[] canEdit = new boolean [] {
                false, false, false, false, false, false, false, false
            };

            public boolean isCellEditable(int rowIndex, int columnIndex) {
                return canEdit [columnIndex];
            }
        });
        tbThongTin.getTableHeader().setReorderingAllowed(false);
        tbThongTin.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                tbThongTinMouseClicked(evt);
            }
        });
        jScrollPane1.setViewportView(tbThongTin);

        jLabel1.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Image/search.png"))); // NOI18N

        btTraCuu.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Image/Search-icon.png"))); // NOI18N
        btTraCuu.setText("Tra Cứu");
        btTraCuu.setBorder(null);
        btTraCuu.setContentAreaFilled(false);
        btTraCuu.setRolloverIcon(new javax.swing.ImageIcon(getClass().getResource("/Image/Search-icon2.png"))); // NOI18N
        btTraCuu.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btTraCuuActionPerformed(evt);
            }
        });

        txtHoTen.setFont(new java.awt.Font("Times New Roman", 0, 13));

        jLabel2.setFont(new java.awt.Font("Times New Roman", 0, 16));
        jLabel2.setText("Họ Tên");

        jLabel3.setFont(new java.awt.Font("Times New Roman", 0, 16));
        jLabel3.setText("Địa chỉ");

        cmbDiaChi.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "NONE", "AND", "OR" }));

        txtDiaChi.setFont(new java.awt.Font("Times New Roman", 0, 13));

        cmbDienThoai.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "NONE", "AND", "OR" }));

        jLabel4.setFont(new java.awt.Font("Times New Roman", 0, 16));
        jLabel4.setText("Điện thoại");

        txtDienThoai.setFont(new java.awt.Font("Times New Roman", 0, 13));
        txtDienThoai.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyTyped(java.awt.event.KeyEvent evt) {
                txtDienThoaiKeyTyped(evt);
            }
        });

        cmbCMND.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "NONE", "AND", "OR" }));

        jLabel5.setFont(new java.awt.Font("Times New Roman", 0, 16));
        jLabel5.setText("CMND");

        txtCMND.setFont(new java.awt.Font("Times New Roman", 0, 13));
        txtCMND.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyTyped(java.awt.event.KeyEvent evt) {
                txtDienThoaiKeyTyped(evt);
            }
        });

        btnSua.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Image/Edit.png"))); // NOI18N
        btnSua.setText("Sửa Phiếu Thuê");
        btnSua.setBorder(null);
        btnSua.setContentAreaFilled(false);
        btnSua.setEnabled(false);
        btnSua.setRolloverIcon(new javax.swing.ImageIcon(getClass().getResource("/Image/Edit2.png"))); // NOI18N
        btnSua.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnSuaActionPerformed(evt);
            }
        });

        jLabel6.setFont(new java.awt.Font("Times New Roman", 1, 18));
        jLabel6.setText("DANH SÁCH KHÁCH HÀNG TÌM ĐƯỢC THEO TỪ KHÓA");

        btsuakh.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Image/Edit.png"))); // NOI18N
        btsuakh.setText("Sửa Thông Tin KH");
        btsuakh.setBorder(null);
        btsuakh.setContentAreaFilled(false);
        btsuakh.setEnabled(false);
        btsuakh.setRolloverIcon(new javax.swing.ImageIcon(getClass().getResource("/Image/Edit2.png"))); // NOI18N
        btsuakh.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btsuakhActionPerformed(evt);
            }
        });

        btnPrint.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Image/Printer.png"))); // NOI18N
        btnPrint.setText("Print");
        btnPrint.setBorder(null);
        btnPrint.setContentAreaFilled(false);
        btnPrint.setRolloverIcon(new javax.swing.ImageIcon(getClass().getResource("/Image/Printer2.png"))); // NOI18N
        btnPrint.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnPrintActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGap(20, 20, 20)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, 202, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addGroup(layout.createSequentialGroup()
                        .addGap(33, 33, 33)
                        .addComponent(jLabel2))
                    .addGroup(layout.createSequentialGroup()
                        .addGap(33, 33, 33)
                        .addComponent(txtHoTen, javax.swing.GroupLayout.PREFERRED_SIZE, 169, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(layout.createSequentialGroup()
                        .addGap(33, 33, 33)
                        .addComponent(cmbDiaChi, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(18, 18, 18)
                        .addComponent(jLabel3, javax.swing.GroupLayout.PREFERRED_SIZE, 82, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(layout.createSequentialGroup()
                        .addGap(33, 33, 33)
                        .addComponent(txtDiaChi, javax.swing.GroupLayout.PREFERRED_SIZE, 169, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(layout.createSequentialGroup()
                        .addGap(33, 33, 33)
                        .addComponent(cmbDienThoai, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(18, 18, 18)
                        .addComponent(jLabel4, javax.swing.GroupLayout.PREFERRED_SIZE, 82, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(layout.createSequentialGroup()
                        .addGap(33, 33, 33)
                        .addComponent(txtDienThoai, javax.swing.GroupLayout.PREFERRED_SIZE, 169, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(layout.createSequentialGroup()
                        .addGap(33, 33, 33)
                        .addComponent(cmbCMND, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(18, 18, 18)
                        .addComponent(jLabel5, javax.swing.GroupLayout.PREFERRED_SIZE, 82, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(layout.createSequentialGroup()
                        .addGap(33, 33, 33)
                        .addComponent(txtCMND, javax.swing.GroupLayout.PREFERRED_SIZE, 169, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addGap(38, 38, 38)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addGap(71, 71, 71)
                        .addComponent(jLabel6))
                    .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 612, javax.swing.GroupLayout.PREFERRED_SIZE)))
            .addGroup(layout.createSequentialGroup()
                .addGap(101, 101, 101)
                .addComponent(btTraCuu)
                .addGap(196, 196, 196)
                .addComponent(btnSua, javax.swing.GroupLayout.PREFERRED_SIZE, 114, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(76, 76, 76)
                .addComponent(btnPrint)
                .addGap(43, 43, 43)
                .addComponent(btsuakh, javax.swing.GroupLayout.PREFERRED_SIZE, 160, javax.swing.GroupLayout.PREFERRED_SIZE))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGap(22, 22, 22)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(jLabel1)
                        .addGap(6, 6, 6)
                        .addComponent(jLabel2)
                        .addGap(5, 5, 5)
                        .addComponent(txtHoTen, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(18, 18, 18)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(layout.createSequentialGroup()
                                .addGap(1, 1, 1)
                                .addComponent(cmbDiaChi, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                            .addComponent(jLabel3))
                        .addGap(11, 11, 11)
                        .addComponent(txtDiaChi, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(11, 11, 11)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(layout.createSequentialGroup()
                                .addGap(1, 1, 1)
                                .addComponent(cmbDienThoai, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                            .addComponent(jLabel4))
                        .addGap(11, 11, 11)
                        .addComponent(txtDienThoai, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(6, 6, 6)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(layout.createSequentialGroup()
                                .addGap(1, 1, 1)
                                .addComponent(cmbCMND, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                            .addComponent(jLabel5))
                        .addGap(11, 11, 11)
                        .addComponent(txtCMND, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(layout.createSequentialGroup()
                        .addGap(10, 10, 10)
                        .addComponent(jLabel6)
                        .addGap(18, 18, 18)
                        .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 363, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addGap(6, 6, 6)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(btTraCuu)
                    .addGroup(layout.createSequentialGroup()
                        .addGap(4, 4, 4)
                        .addComponent(btnSua))
                    .addGroup(layout.createSequentialGroup()
                        .addGap(4, 4, 4)
                        .addComponent(btnPrint))
                    .addGroup(layout.createSequentialGroup()
                        .addGap(4, 4, 4)
                        .addComponent(btsuakh))))
        );

        jLabel3.getAccessibleContext().setAccessibleName("");
        jLabel6.getAccessibleContext().setAccessibleName("");

        java.awt.Dimension screenSize = java.awt.Toolkit.getDefaultToolkit().getScreenSize();
        setBounds((screenSize.width-942)/2, (screenSize.height-538)/2, 942, 538);
    }// </editor-fold>//GEN-END:initComponents

private void btTraCuuActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btTraCuuActionPerformed
       Tracuu();
}//GEN-LAST:event_btTraCuuActionPerformed
private void Tracuu()
{
    String  where="TenKH like N'%"+txtHoTen.getText()+"%'";
       if(!(cmbDiaChi.getSelectedItem().toString().equals("NONE")))
       {
           where=where+" " + cmbDiaChi.getSelectedItem().toString()+" DiaChi like N'%"+txtDiaChi.getText()+"%'";
       }
       if(!(cmbDienThoai.getSelectedItem().toString().equals("NONE")))
       {
           where=where+ " "+ cmbDienThoai.getSelectedItem().toString()+" SDT like N'%"+txtDienThoai.getText()+"%'";
       }
       if(!cmbCMND.getSelectedItem().toString().equals("NONE"))
       {
           where= where+ " "+ cmbCMND.getSelectedItem().toString()+" CMND Like N'%"+txtCMND.getText()+"%'";
       }
       Showds(where);
}
private void Showds(String where)
{
    try
    {
        WebRowSet wrs=KhachHangController.khachHang_GetByTop("",where, "");
        Object data[]=new Object[8];
        tbThongTin.setToolTipText("Danh sách khách hàng tìm thấy!");
        DefaultTableModel model=(DefaultTableModel) tbThongTin.getModel(); 
        while(model.getRowCount()>0)
        {
            model.removeRow(0);
        }
        SimpleDateFormat sdf = new SimpleDateFormat("dd-M-yyyy");
        while(wrs.next())
        {
            if(wrs.getString("MaKh")!=null){
              data[0]="KH" + wrs.getString("MaKh").trim();
            }
            else data[0]="KH" + wrs.getString("MaKh");

            if(wrs.getString("TenKH")!=null){
                data[1]=wrs.getString("TenKH").trim();
            }
            else data[1]=wrs.getString("TenKH");

            if(wrs.getString("GioiTinh")!=null){
                data[2]=wrs.getString("GioiTinh").trim();
            }
            else data[2]=wrs.getString("GioiTinh");

            if(wrs.getString("DiaChi")!=null){
                data[3]=wrs.getString("DiaChi").trim();
            }
            else data[3]=wrs.getString("DiaChi");

            Date d = wrs.getDate("NgaySinh");
                data[4] = sdf.format(d);
             if(wrs.getString("SDT")!=null){
                data[5]=wrs.getString("SDT").trim();
            }
            else data[5]=wrs.getString("SDT");

            if(wrs.getString("CMND")!=null){
                data[6]=wrs.getString("CMND").trim();
            }
            else data[6]=wrs.getString("CMND");

            if(wrs.getString("QuocTich")!=null){
                data[7]=wrs.getString("QuocTich").trim();
            }
            else data[7]=wrs.getString("QuocTich");
            model.addRow(data);
        }
    }
    catch(Exception e)
    {
        JOptionPane.showMessageDialog(new JFrame(), "Đường truyền bị gián đoạn ! Xin vui lòng kiểm tra lại", "Test Connect", JOptionPane.INFORMATION_MESSAGE);
    }
}
private void formComponentShown(java.awt.event.ComponentEvent evt) {//GEN-FIRST:event_formComponentShown
// TODO add your handling code here:
    try
    {
        Tracuu();
    }
    catch(Exception e)
    {
         JOptionPane.showMessageDialog(this, e.getMessage(), "Thông báo", JOptionPane.ERROR_MESSAGE);
    }
}//GEN-LAST:event_formComponentShown

private void btnSuaActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnSuaActionPerformed
// TODO add your handling code here:
    
    try
    {
        int sel_row=tbThongTin.getSelectedRow();
        if(sel_row == -1) 
        {
            JOptionPane.showMessageDialog(rootPane, "Bạn chưa chọn thông tin cần sửa.","Warning",JOptionPane.WARNING_MESSAGE);
            return;
        }
        String MaKH = tbThongTin.getValueAt(sel_row,0).toString().substring(2);
        WebRowSet wrs = PhieuThueController.phieuThue_GetByTop("", " MaKH = '"+ MaKH +"' ", "");
        if(wrs.next())
        {
            String t_MaPT,t_MP;
            t_MaPT = wrs.getString("MaPhieuThue");
            t_MP = wrs.getString("MaPhong");
            WebRowSet wr = HoaDonController.hoaDon_GetByTop("", " MaPhieuThue = '"+t_MaPT+"' ", "");
            HoaDonDTO hd = new HoaDonDTO();
            hd.setMaHD("");
            if(wr.next())//hóa đơn đa được lập
            {
                if(JOptionPane.showConfirmDialog(this, "Phiếu thuê đã được thanh toán. Bạn có muốn xem hóa đơn không?", "Question",JOptionPane.YES_NO_OPTION)==JOptionPane.YES_OPTION)
                {
                    hd.setMaHD(wr.getString("MaHD"));
                    hd.setTienDV(wr.getString("TienDV").replace(".0000", ""));
                    hd.setTongTien(wr.getString("TongTien").replace(".0000", ""));
                    frmHoaDon frmhd = new frmHoaDon();
                    frmhd.MaKH = MaKH;
                    frmhd.MaPhieuThue = t_MaPT;
                    frmhd.MaPhong= t_MP;
                    frmhd.HD = hd;
                    try
                    {
                        //SimpleDateFormat sdf = new SimpleDateFormat("dd-M-yyyy");
                        DateFormat df = new SimpleDateFormat("dd-M-yyyy");//(jtdanhsach.getValueAt(jtdanhsach.getSelectedRow(), 4));
                        Date d1 = df.parse(df.format(wrs.getDate("NgayDi")));
                        Date d2 = df.parse(df.format(wrs.getDate("NgayThue")));
                        frmhd.SoNgay = getcountday(d1.getYear() + 1900, d1.getMonth() + 1, d1.getDate(), d2.getYear() + 1900, d2.getMonth() + 1, d2.getDate());
                    }
                    catch(Exception e){ frmhd.SoNgay = 0;}
                    frmhd.setVisible(true);  
                    frmhd.setFocusable(true);
                    frmhd.preframe = 1;
                    _frmtc = this;
                    this.setVisible(false);
                    return;
                }
                else return;//không muốn cập nhật
            }

            frmDatPhong frmdp = new frmDatPhong();
            frmdp.MaKH = MaKH;
            frmdp.MaPT = t_MaPT;
            frmdp.MP = t_MP;
            frmdp.preframe = 2;
            frmdp.set_phieudatphong();
            frmdp.setVisible(true);
            frmdp.setFocusable(true);
            _frmtc = this;
            this.setVisible(false);
        }

    }
    catch(Exception e)
    {
        JOptionPane.showMessageDialog(new JFrame(), "Đường truyền bị gián đoạn ! Xin vui lòng kiểm tra lại", "Test Connect", JOptionPane.INFORMATION_MESSAGE);
    }
}//GEN-LAST:event_btnSuaActionPerformed

private void tbThongTinMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_tbThongTinMouseClicked
// TODO add your handling code here:
    btnSua.setEnabled(true);
    btsuakh.setEnabled(true);
    int sel_row=tbThongTin.getSelectedRow();
    kh.setMaKH(tbThongTin.getValueAt(sel_row,0).toString().substring(2));

}//GEN-LAST:event_tbThongTinMouseClicked

private void formWindowClosed(java.awt.event.WindowEvent evt) {//GEN-FIRST:event_formWindowClosed
// TODO add your handling code here:
    frmMain._main.setVisible(true);
    frmMain._main.setFocusable(true);
    this.setDefaultCloseOperation(DISPOSE_ON_CLOSE);
}//GEN-LAST:event_formWindowClosed

private void txtDienThoaiKeyTyped(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_txtDienThoaiKeyTyped
    char c = evt.getKeyChar();
    if(!Character.isDigit(c) )
    {
        evt.consume();
    }
    // TODO add your handling code here:
}//GEN-LAST:event_txtDienThoaiKeyTyped

private void btsuakhActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btsuakhActionPerformed
    try
    {
        int sel_row=tbThongTin.getSelectedRow();
        if(sel_row == -1) 
        {
            JOptionPane.showMessageDialog(rootPane, "Bạn chưa chọn thông tin cần sửa.","Warning",JOptionPane.WARNING_MESSAGE);
            return;
        }
         WebRowSet wrs=KhachHangController.khachHang_GetById(kh.getMaKH());
         wrs.next();
         kh.setTenKH(wrs.getObject("TenKH").toString());
         kh.setCMND(wrs.getObject("CMND").toString());
         kh.setDiaChi(wrs.getObject("DiaChi").toString());
         Date date=(Date) wrs.getObject("NgaySinh");
         kh.setNgaySinh(date.getDate()+ "-" +(date.getMonth() + 1 )+ "-"+  (date.getYear() + 1900));
         kh.setQuocTich(wrs.getObject("QuocTich").toString());
         kh.setSDT(wrs.getObject("SDT").toString());
         kh.setGioiTinh(wrs.getObject("GioiTinh").toString());
         frmKhachHang frm = new frmKhachHang(this);
         frm.setVisible(true);
         frm.setFocusable(true);
         this.setVisible(false);
    }
    catch(Exception e)
    {
        JOptionPane.showMessageDialog(new JFrame(), "Đường truyền bị gián đoạn ! Xin vui lòng kiểm tra lại", "Test Connect", JOptionPane.INFORMATION_MESSAGE);
    }
    // TODO add your handling code here:
}//GEN-LAST:event_btsuakhActionPerformed

private void btnPrintActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnPrintActionPerformed

    try {
            // TODO add your handling code here:
            String html1 = "";//<meta http-equiv=Content-Type content='text/html; charset=utf8'>";
            //html1 += "<LEFT>CỘNG HÒA XÃ HỘI CHỦ NGHĨA VIỆT NAM</BR>----------Ðộc lập - Tự do - Hạnh phúc-----------</LEFT>";
            html1 += "<CENTER><h2>DANH SÁCH KHÁCH HÀNG</h2>"; 
//            html1 += "&nbsp;&nbsp;&nbsp<b>Năm : </b>" + ycNam.getYear();

            String footer ="";
//            footer += "<b>Tiền phòng : </b>" + lbTienPhong.getText() + " VNĐ<br>";
//            footer += "&nbsp;&nbsp;&nbsp<b>Tiền dịch vụ : </b>" + lbTienDV.getText() + " VNĐ<br>";
//            footer += "&nbsp;&nbsp;&nbsp<b>Tổng doanh thu : </b>" + lbDoanhThu.getText() + " VNĐ<br>";
            BaoCao bc = new BaoCao();
            bc.baocao(tbThongTin,html1,footer,"400");
        } catch (Exception ex) {
            Logger.getLogger(frmBaoCao.class.getName()).log(Level.SEVERE, null, ex);
        }

    // TODO add your handling code here:
}//GEN-LAST:event_btnPrintActionPerformed
private int between2date(Calendar ngaysau,Calendar ngaytruoc)
    {
        return (int) ((ngaysau.getTime().getTime() - ngaytruoc.getTime().getTime())/(24*3600*1000));
        
    }
    public int getcountday(int y1, int m1,int d1,int y2, int m2,int d2)
    {
        //y1 - y2
            Calendar ngaythue = Calendar.getInstance();
            Calendar ngaydi = Calendar.getInstance();
            Calendar temp = Calendar.getInstance();
            int namthue;
           // namdi = y1;
            namthue = y2;
            ngaythue.set(y2,m2,d2);
            ngaydi.set(y1,m1,d1);
            temp.set(y1,m1,d1);
           
            int days = 0;
            if(y1 > namthue)
            {
                ngaydi.set(namthue,12,31);
                days = between2date(ngaydi, ngaythue);
                namthue++;
                if(y1 > namthue)
                {
                    days += 365*(y1 - namthue);
                }
                ngaythue.set(y1,1,1);
                days += between2date(temp, ngaythue)+2;
            }
            else
            {
                days = between2date(ngaydi, ngaythue) + 1;
            }
//            JOptionPane.showConfirmDialog(rootPane, days);
            return days;
    }
    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        /* Set the Nimbus look and feel */
        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
        /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
         * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html 
         */
        try {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                if ("Nimbus".equals(info.getName())) {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        } catch (ClassNotFoundException ex) {
            java.util.logging.Logger.getLogger(frmTraCuu.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(frmTraCuu.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(frmTraCuu.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(frmTraCuu.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        //</editor-fold>

        /* Create and display the form */
        java.awt.EventQueue.invokeLater(new Runnable() {

            public void run() {
                new frmTraCuu().setVisible(true);
            }
        });
    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton btTraCuu;
    private javax.swing.JButton btnPrint;
    private javax.swing.JButton btnSua;
    private javax.swing.JButton btsuakh;
    private javax.swing.JComboBox cmbCMND;
    private javax.swing.JComboBox cmbDiaChi;
    private javax.swing.JComboBox cmbDienThoai;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JTable tbThongTin;
    private javax.swing.JTextField txtCMND;
    private javax.swing.JTextField txtDiaChi;
    private javax.swing.JTextField txtDienThoai;
    private javax.swing.JTextField txtHoTen;
    // End of variables declaration//GEN-END:variables
}
